from pydantic import BaseModel, field_validator, Field
from typing import Optional, List
from datetime import datetime

# 请求体模型
class UserRequest(BaseModel):
    user_query: str  # 用户的自然语言查询
    phone_number: Optional[str] = Field(None, description="用户手机号，dify类别可为空")  # 修改此行
    debug: Optional[bool] = False 

class AnalysisRequest(BaseModel):
    user_query: str
    phone_number: Optional[str] = None 
    conversation_id: Optional[str] = None 
    debug: bool = False
    include_analysis: Optional[bool] = None  # None表示自动判断
    include_chart: Optional[bool] = None    # None表示自动判断
    is_monitor: bool = False  # 是否为监控请求，监控请求将绕过缓存

class UnitDateParams(BaseModel):
    unitId: str = Field(..., max_length=11, description="运营单位号")
    startDate: str = Field(..., pattern=r'^\d{8}$', description="开始日期(YYYYMMDD)")
    endDate: str = Field(..., pattern=r'^\d{8}$', description="结束日期(YYYYMMDD)")

class SettFileDownParams(BaseModel):
    fileId: str = Field(..., max_length=64, description="文件ID")
    unitId: str = Field(..., max_length=11, description="清算单位号")
    tbNo: str = Field(..., max_length=40, description="轧差表编号")

class ETCInvoiceParams(BaseModel):
    userId: str = Field(..., min_length=1, max_length=20, description="用户ID")
    kpMerid: List[str] = Field(..., description="开票商户ID列表")
    kpMonth: str = Field(..., pattern=r'^\d{6}$', description="开票月份(YYYYMM)")
    start: int = Field(0, ge=0, description="开始页数，从0开始")
    limit: int = Field(10, ge=1, le=100, description="每页条数")
    kpStat: Optional[str] = Field(None, description="开票状态，如'01'=成功")
    kpType: Optional[str] = Field(None, description="开票类型，如'10'=电子票")

class ETCSettParams(BaseModel):
    startDate: str = Field(..., pattern=r'^\d{8}$', description="开始日期(YYYYMMDD)")
    endDate: str = Field(..., pattern=r'^\d{8}$', description="结束日期(YYYYMMDD)")
    subStationIds: Optional[List[str]] = Field(None, description="子站点ID列表")
